package com.example.takeoutfood.ui;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.constraintlayout.widget.ConstraintLayout;

import com.example.takeoutfood.R;

public class ShopDiscountLayout extends ConstraintLayout {
    ConstraintLayout cl_discount;
    ConstraintLayout cl_discount_expanded;
    //默认不展开
    boolean mIsExpanded = false;
    public ShopDiscountLayout(@NonNull Context context, @Nullable AttributeSet attrs) {
        super(context, attrs);

        LayoutInflater.from(context).inflate(R.layout.layout_shop_details_discount,this);
        cl_discount = findViewById(R.id.cl_discount);
        cl_discount_expanded = findViewById(R.id.cl_discount_expanded);
        cl_discount.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                swit(mIsExpanded);
            }
        });
        cl_discount_expanded.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                swit(mIsExpanded);
            }
        });
    }

    private void swit(boolean expand){
        if (expand){
            //已经打开第二页面，要回到第一个页面
            cl_discount_expanded.setAlpha(0f);
            cl_discount.setAlpha(1.0f);
        }else {
            //打开第二个页面

            cl_discount.setAlpha(0f);
            cl_discount_expanded.setAlpha(1.0f);
        }

        mIsExpanded = !expand;

    }
}
